import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_app/utils/UIData.dart';
import 'package:flutter_app/utils/ImageUtils.dart';
import 'package:flutter_app/ui/widgets/skip_down_time.dart';


class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => new _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> implements OnSkipClickListener{

  var welcomeImageUrl = '';

  void navigationPage() {
    Navigator.of(context).pushReplacementNamed(UIData.loginRoute);
  }

  @override
  void onSkipClick() {
    navigationPage();
  }

  @override
  void initState() {
    super.initState();
//    _getWelcomeImage();
//    _delayedGoHomePage();
    //1.先加载启动页图片
    _loadSplashData();
    //2.判断是否需要展示引导页
    _initAsync();
  }

  _delayedGoHomePage() {
    Future.delayed(new Duration(seconds: 5), () {
      _goHomePage();
    });
  }

  _goHomePage() {
    Navigator.of(context).pushReplacementNamed(UIData.loginRoute);
  }

  _getWelcomeImage() async {
    String cover = 'http://pic48.nipic.com/file/20140912/7487939_224705141000_2.jpg';
    setState(() {
      welcomeImageUrl = cover;
    });
  }

  void _loadSplashData() async {
  }

  void _initAsync() async {
  }

  List<String> _guideList = [
    ImageUtils.getImgPath('guide1'),
    ImageUtils.getImgPath('guide2'),
    ImageUtils.getImgPath('guide3'),
    ImageUtils.getImgPath('guide4'),
  ];

  @override
  Widget build(BuildContext context) {
    return new Stack(
      alignment: Alignment.bottomCenter,
      children: <Widget>[
        new Container(
          color: Colors.white,
          child: new Image.network(
            welcomeImageUrl,
            fit: BoxFit.cover,
          ),
          constraints: new BoxConstraints.expand(),
        ),
        new Image.asset(
          'assets/images/welcome_logo.jpg',
          fit: BoxFit.fitWidth,
        ),
        new Container(
          child: Align(
            alignment: Alignment.topRight,
            child: new Container(
              padding: const EdgeInsets.only(top: 30.0, right: 20.0),
              child: new SkipDownTimeProgress(
                Colors.red,
                22.0,
                new Duration(seconds: 5),
                new Size(25.0, 25.0),
                skipText: "跳过",
                clickListener: this,
              ),
            ),
          ),
        ),
      ],
    );
  }
}